<?php
require_once dirname(__FILE__). '/../lib/db/db.php';
require_once dirname(__FILE__). '/../lib/theme/theme.php';

class Config {
	private $__config = array();
	public $DB;	
	function __construct($build=true){
		if ($build){
			$this->buildCof();
			$this->DB = new Database($this);
		}
	}
	
	public function get($name){
		return $this->__config[$name];
	}
	
	public function set($name, $val){
		return $this->__config[$name] = $val;
	}
	
	private function buildCof(){
		$this->__config["SITENAME"] = "VidBox - Your vide box!";
		$this->__config["SMTPHOST"] = "localhost"; //smtp bilgileri gelecek
		$this->__config["SITEURL"] = "http://localhost/vidbox";
		$this->__config["API"] = $this->buildApiCof();
		$this->__config["DB"] = $this->buildDBCof();
		$this->__config["UPDATE"] = $this->buildUpdateCof();
		$this->__config["THEME"] = $this->buildThemeCof();
	}
	
	private function buildThemeCof(){
		$config = new Config(false);
		$theme = new theme($this);	
		$config->__config["INDEX"] = $theme->INDEX();
		$config->__config["LOGIN"] = $theme->LOGIN();
		return $config; 	
	}
	
	private function buildUpdateCof(){
		$config = new Config(false);
		$config->__config["APPVERSION"] = "1.0";
		$config->__config["APIVERSION"] = "1.0";
		$config->__config["APPFILENAME"] = $this->__config["SITEURL"]."/downloads/VidBox_v".$config->__config["APPVERSION"].".exe";
		return $config; 	
	}
	
	private function buildDBCof(){
		$config = new Config(false);
		$config->__config["DBHOST"] = "localhost";
		$config->__config["DBNAME"] = "vidboxdb";
		$config->__config["USER"] = "root";
		$config->__config["PASS"] = "";
		return $config; 	
	}
	
	
	private function buildApiCof(){
		$config = new Config(false);
		$config->__config["APIACCES"] = true;
		$config->__config["APIVERSION"] = "1.0";
		$config->__config["APILIST"] = $this->__list_api_conf();
		$config->__config["APIPLAYER"] = $this->__player_api_conf();	
		$config->__config["APISERVERSOAP"] = $this->__serversoap_api_conf();	
		return $config; 	
	}
	
	private function __serversoap_api_conf(){
		$config = new Config(false);
		$config->__config["APIACCES"] = ($_SERVER['HTTP_USER_AGENT'] == 'VIDBOXCLIENTv1.0');
		$config->__config["APIVERSION"] = "1.0";
		return $config;		
	}
	
	private function __player_api_conf(){
		$config = new Config(false);
		$config->__config["APIACCES"] = true;
		$config->__config["APIVERSION"] = "1.0";
		return $config;		
	}
	
	private function __list_api_conf(){
		$config = new Config(false);
		$config->__config["APIACCES"] = true;
		$config->__config["APIVERSION"] = "1.0";
		$config->__config["TVAPI"] = $this->__tv_api_Conf();
		$config->__config["MOVIEAPI"] = $this->__movie_api_Conf();
		$config->__config["VIDEOAPI"] = $this->__video_api_Conf();
		$config->__config["TRAILERAPI"] = $this->__trailer_api_Conf();
		$config->__config["SEARCH"] = $this->__search_api_Conf();
		return $config;		
	}
	
	private function __search_api_conf(){
		$config = new Config(false);
		$config->__config["APIACCES"] = true;
		$config->__config["APIVERSION"] = "1.0";
		$config->__config["APITYPE"] = "SEARCH";
		$config->__config["APIFILENAME"] = "";
		$config->__config["APIPLAYER"] = "";
		return $config;		
	}
	
	private function __tv_api_conf(){
		$config = new Config(false);
		$config->__config["APIACCES"] = true;
		$config->__config["APIVERSION"] = "1.0";
		$config->__config["APITYPE"] = "FILE";
		$config->__config["APIFILENAME"] = "tv.txt";
		$config->__config["APIPLAYER"] = "MP";
		
		return $config;		
	}
	
	private function __movie_api_conf(){
		$config = new Config(false);
		$config->__config["APIACCES"] = true;
		$config->__config["APIVERSION"] = "1.0";
		$config->__config["APITYPE"] = "SITEMAP";
		$config->__config["APIFILENAME"] = "";
		$config->__config["APIPLAYER"] = "FLASH";
		return $config;		
	}
	
	private function __video_api_conf(){
		$config = new Config(false);
		$config->__config["APIACCES"] = true;
		$config->__config["APIVERSION"] = "1.0";
		$config->__config["APITYPE"] = "SITEMAP";
		$config->__config["APIFILENAME"] = "video.txt";
		$config->__config["APIPLAYER"] = "FLASH";
		return $config;		
	}
	
	private function __trailer_api_conf(){
		$config = new Config(false);
		$config->__config["APIACCES"] = true;
		$config->__config["APIVERSION"] = "1.0";
		$config->__config["APITYPE"] = "YOUTUBE";
		$config->__config["APIFILENAME"] = "trailer.txt";
		$config->__config["APIPLAYER"] = "FLASH";
		return $config;		
	}
	
	
}
?>